# Read in a dataset and store the information in a table.
# Takes a path to the data file.
# Returns the data in a table.

import os
import sys

def readData(dataFn):
   rawData = open(dataFn)

   # Read the data into an array.
   data = []

   for l in rawData:
      line = l.split(',')
      thisRow = []

      for i in range(7):
         thisRow.append(float(line[i].strip()))

      data.append(thisRow)

   return data

# Read each dataset in a folder and return a  3D table with all of the
# information. Assumes that the data sets are labeled sequentially.

def readAllData(paramFile):
   endReached = False;

   i = 0
   data = []
   dataFolder = "../data"

   inf = open(paramFile)

   prefix = "DD"
   nZeros = 4

   for line in inf:
      ele = line.split("=")

      if (ele[0].strip() == "OutputPrefix"):
         prefix = ele[1].strip()
      if (ele[0].strip() == "ZerosInOutputName"):
         nZeros = int(ele[1].strip())

   while os.path.exists(dataFolder + "/" + prefix + str(i).zfill(nZeros)):
      dataFn = dataFolder + "/DD" + str(i).zfill(nZeros);
      dataSet = readData(dataFn)

      data.append(dataSet)

      i = i + 1

   return data
